package com.ellfors.common.ext

import android.graphics.drawable.Drawable
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder
import com.ellfors.common.R

val IMG_PLACE_HOLDER = R.drawable.ic_developer
val IMG_ERROR = R.drawable.ic_developer

fun ImageView?.loadImg(url: String?) {
    this ?: return
    Glide
        .with(context)
        .load(url)
        .centerCrop()
        .placeholder(IMG_PLACE_HOLDER)
        .error(IMG_ERROR)
        .into(this)
}

fun ImageView?.loadImg(res: Int?) {
    this ?: return
    Glide
        .with(context)
        .load(res)
        .centerCrop()
        .placeholder(IMG_PLACE_HOLDER)
        .error(IMG_ERROR)
        .into(this)
}

fun ImageView?.loadImageCustom(
    url: String?, build: RequestBuilder<Drawable>.() -> Unit = {}
) {
    this ?: return
    val request = Glide.with(context).load(url)
    request.build()
    request.into(this)
}
